/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogEditUser.java
 *
 * Created on Jun 11, 2012, 9:27:22 PM
 */
package com.ebdesk.view.masterdata;

import com.ebdesk.view.masterdata.*;
import com.ebdesk.view.masterdata.*;
import com.ebdesk.controller.masterdata.UserController;
import com.ebdesk.controller.masterdata.Validator;
import com.ebdesk.model.masterdata.User;
import java.awt.Color;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Acer
 */
public class DialogDetailUser extends javax.swing.JDialog {
    private User user;
    
    private static UserController userController;
    /** Creates new form DialogEditUser */
    public DialogDetailUser(java.awt.Frame parent, boolean modal, User user) {
        super(parent, modal);
        this.user = this.user;
        
        userController = new UserController();
        
        this.setLocationRelativeTo(null);
        try {
                        // Set System L&F
                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                } 
                catch (UnsupportedLookAndFeelException e) {
                   // handle exception
                }
                catch (ClassNotFoundException e) {
                   // handle exception
                }
                catch (InstantiationException e) {
                   // handle exception
                }
                catch (IllegalAccessException e) {
                   // handle exception
                }
        
        initComponents();
        userUsername.setText(user.getUsername());
        userName.setText(user.getName());
        userEmail.setText(user.getEmail());
        userPassword.setText(user.getPassword());
        userCreatedBy.setText(user.getCreated_by());
        userCreatedDate.setText(user.getCreated_date() == null ? "" : user.getCreated_date().toString());
        userUserType.setText(user.getUser_type() == 1? "Admin" : "Non Admin");
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        panelInput = new javax.swing.JPanel();
        labelUsername = new javax.swing.JLabel();
        labelName = new javax.swing.JLabel();
        labelEmail = new javax.swing.JLabel();
        labelPassword = new javax.swing.JLabel();
        labelUserType = new javax.swing.JLabel();
        buttonSave = new javax.swing.JButton();
        labelCreatedBy = new javax.swing.JLabel();
        labelCreatedDate = new javax.swing.JLabel();
        userUsername = new javax.swing.JLabel();
        userName = new javax.swing.JLabel();
        userEmail = new javax.swing.JLabel();
        userPassword = new javax.swing.JLabel();
        userCreatedBy = new javax.swing.JLabel();
        userCreatedDate = new javax.swing.JLabel();
        userUserType = new javax.swing.JLabel();

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("User Detail");
        setIconImage(null);
        setModal(true);
        setName("detailUser"); // NOI18N

        panelInput.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        labelUsername.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelUsername.setText("Username :");

        labelName.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelName.setText("Name :");

        labelEmail.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelEmail.setText("Email :");

        labelPassword.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelPassword.setText("Password :");

        labelUserType.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        labelUserType.setText("User Type :");

        buttonSave.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        buttonSave.setText("OK");
        buttonSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSaveActionPerformed(evt);
            }
        });

        labelCreatedBy.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        labelCreatedBy.setText("Created by :");

        labelCreatedDate.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        labelCreatedDate.setText("Created Date :");

        userUsername.setText("userUsername");

        userName.setText("userName");

        userEmail.setText("userEmail");

        userPassword.setText("userPassword");

        userCreatedBy.setText("userCreatedBy");

        userCreatedDate.setText("userCreatedDate");

        userUserType.setText("userUserType");

        javax.swing.GroupLayout panelInputLayout = new javax.swing.GroupLayout(panelInput);
        panelInput.setLayout(panelInputLayout);
        panelInputLayout.setHorizontalGroup(
            panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelInputLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelInputLayout.createSequentialGroup()
                        .addComponent(labelUsername)
                        .addGap(55, 55, 55)
                        .addComponent(userUsername))
                    .addGroup(panelInputLayout.createSequentialGroup()
                        .addComponent(labelName)
                        .addGap(81, 81, 81)
                        .addComponent(userName))
                    .addGroup(panelInputLayout.createSequentialGroup()
                        .addComponent(labelEmail)
                        .addGap(83, 83, 83)
                        .addComponent(userEmail))
                    .addGroup(panelInputLayout.createSequentialGroup()
                        .addComponent(labelPassword)
                        .addGap(59, 59, 59)
                        .addComponent(userPassword))
                    .addGroup(panelInputLayout.createSequentialGroup()
                        .addComponent(labelCreatedBy)
                        .addGap(51, 51, 51)
                        .addComponent(userCreatedBy))
                    .addGroup(panelInputLayout.createSequentialGroup()
                        .addComponent(labelCreatedDate)
                        .addGap(38, 38, 38)
                        .addComponent(userCreatedDate))
                    .addGroup(panelInputLayout.createSequentialGroup()
                        .addComponent(labelUserType)
                        .addGap(56, 56, 56)
                        .addGroup(panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(buttonSave)
                            .addComponent(userUserType))))
                .addContainerGap(123, Short.MAX_VALUE))
        );
        panelInputLayout.setVerticalGroup(
            panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelInputLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelUsername)
                    .addComponent(userUsername))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelName, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(userName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelEmail)
                    .addComponent(userEmail))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelPassword)
                    .addComponent(userPassword))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelCreatedBy)
                    .addComponent(userCreatedBy))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelCreatedDate)
                    .addComponent(userCreatedDate))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelUserType)
                    .addComponent(userUserType))
                .addGap(18, 18, 18)
                .addComponent(buttonSave)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelInput, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed
    this.setVisible(false);
}//GEN-LAST:event_buttonSaveActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
                
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    DialogDetailUser dialog = new DialogDetailUser(new javax.swing.JFrame(), true, new UserController().getUserManagement().getUser("admin"));
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                        @Override
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(DialogDetailUser.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonSave;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel labelCreatedBy;
    private javax.swing.JLabel labelCreatedDate;
    private javax.swing.JLabel labelEmail;
    private javax.swing.JLabel labelName;
    private javax.swing.JLabel labelPassword;
    private javax.swing.JLabel labelUserType;
    private javax.swing.JLabel labelUsername;
    private javax.swing.JPanel panelInput;
    private javax.swing.JLabel userCreatedBy;
    private javax.swing.JLabel userCreatedDate;
    private javax.swing.JLabel userEmail;
    private javax.swing.JLabel userName;
    private javax.swing.JLabel userPassword;
    private javax.swing.JLabel userUserType;
    private javax.swing.JLabel userUsername;
    // End of variables declaration//GEN-END:variables
}
